'use strict';
const {
    Model,
    INTEGER,
    DATE
} = require('sequelize');
const moment = require('moment')
module.exports = (sequelize, DataTypes) => {
    // class driver extends Model {
    //   /**
    //    * Helper method for defining associations.
    //    * This method is not a part of Sequelize lifecycle.
    //    * The `models/index` file will call this method automatically.
    //    */
    //   static associate(models) {
    //     // define association here
    //   }
    // };
    const receipt = sequelize.define('receipt', {
        ReceiptID: {
            allowNull: false,
            primaryKey: true,
            type: DataTypes.INTEGER,
            autoIncrement: true
        },
        TruckLic: {
            type: DataTypes.STRING,
            unique: false
        },
        PhoneNum: {
            type: DataTypes.STRING,
            allowNull: false
        },
        ReceiptStatus: {
            type: DataTypes.INTEGER,
        },
        CouponStatus: {
            type: DataTypes.INTEGER,
            allowNull: false
        },
        WorkMode: {
            type: DataTypes.INTEGER
        },
        CreateTime: {
            type: DataTypes.DATE(),
            get() {
                return moment(this.getDataValue('CreateTime')).utcOffset('+00:00').format('MM-DD HH:mm:ss');
            }
        },
        IsReActive: {
            type: DataTypes.INTEGER,
            default: 0
        },
        ActiveTime: {
            type: DataTypes.DATE(),
        },
        SaveTime: {
            type: DataTypes.DATE()
        },
        WorkID: {
            type: DataTypes.STRING
        },
        ResvID: {
            type: DataTypes.STRING
        },
        ContainerID: {
            type: DataTypes.STRING,
            allowNull: false
        },
        ContainerPlace: {
            type: DataTypes.STRING
        },
        ContainerWeight: {
            type: DataTypes.STRING
        },
        ContainerLoadometerWeight: {
            type: DataTypes.STRING,
        },
        ContainerFrom: {
            type: DataTypes.STRING
        },
        ContainerType: {
            type: DataTypes.STRING
        },
        ContainerStatus: {
            type: DataTypes.INTEGER
        },
        ContainerOwner: {
            type: DataTypes.STRING
        },
        ContainerDangerCat: {
            type: DataTypes.STRING,
        },
        ContainerLimit: {
            type: DataTypes.STRING
        },
        ContainerCold: {
            type: DataTypes.STRING
        },
        ContainerFB: {
            type: DataTypes.STRING
        },
        ContainerTemp: {
            type: DataTypes.DOUBLE,
        },
        Channel: {
            type: DataTypes.STRING
        },
        GetTickID: {
            type: DataTypes.STRING
        }
    }, {
        timestamps: false
    });
    receipt.associate = function(models) {
        receipt.hasOne(models.coupon, {
            foreignKey: 'ReceiptID',
            sourceKey: 'ReceiptID'
        })
        receipt.belongsTo(models.truck, {
            foreignKey: 'TruckLic',
            targetKey: 'TruckLic',
            as: 'truck',
            constraints: false
        })

    }
    return receipt;
};